'''
    实现对ini文件内容的相关操作行为
'''
import configparser
import pathlib

import yaml

# 获取配置文件的绝对路径
file = pathlib.Path(__file__).parents[0].resolve() / 'server.ini'
conf = configparser.ConfigParser()


# 读取ini文件
def read_conf(section, option):
    conf.read(file)
    values = conf.get(section=section, option=option)
    return values


# 写入ini文件
def write_conf(section, option, value):
    print(value)
    conf.read(file)
    conf.set(section=section, option=option, value=value)
    # 将指定的内容写入到conf文件之中。
    conf.set(section, option, value)
    with open(file, 'w') as f:
        conf.write(f)


# yaml数据的读取
def yaml_read(data_file):
    with open(data_file, 'r', encoding='utf-8') as f:
        values = yaml.safe_load(f)
    return values
